package org.codert;

import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @author: TanJingyu
 * @create: 2021-05-06 14:00
 **/
@EnableAspectJAutoProxy(exposeProxy = true, proxyTargetClass = true)
@EnableAsync
@SpringBootApplication
@EnableJpaRepositories(basePackages = "org.codert.domain")
//@Import(value = Application.ApplicationInner.class)
public class Application implements ApplicationContextAware, ApplicationEventPublisherAware {
    public static ApplicationContext applicationContext;
    private ApplicationEventPublisher applicationEventPublisher;

    public static void main(String[] args) {
//        new ApplicationInner();
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Application.applicationContext = applicationContext;
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public static class ApplicationInner {
        static {
            System.out.println(Application.applicationContext);
        }
    }
}
